/**
 * ==========================================================================
 * 增强交互系统 - 移动端优化和现代化交互
 * 补充 ilovefree-migration.js 的移动端功能
 * ==========================================================================
 */

class EnhancedInteractions {
    constructor() {
        this.isMobile = window.innerWidth <= 768;
        this.menuOpen = false;
        this.searchOpen = false;
        this.theme = localStorage.getItem('theme') || 'light';
        this.init();
    }

    /**
     * 初始化增强交互功能
     */
    init() {
        this.initializeMobileMenu();
        this.initializeThemeToggle();
        this.initializeSearch();
        this.setupScrollEffects();
        this.setupImageLazyLoading();
        this.setupTouchGestures();
        this.initializePerformanceOptimizations();
        this.bindGlobalEvents();
        this.setupCategoryAnimations();
        this.setupTagInteractions();
        this.setupNavigationEnhancements();
        this.setupAccessibilityFeatures();
        console.log('✨ 增强交互系统已初始化');
    }

    /**
     * 初始化移动端菜单
     */
    initializeMobileMenu() {
        const menuToggle = document.getElementById('mobileMenuToggle');
        const mainNav = document.querySelector('.main-nav');
        const body = document.body;

        if (menuToggle && mainNav) {
            // 菜单切换
            menuToggle.addEventListener('click', () => {
                this.toggleMobileMenu();
            });

            // 点击菜单项关闭菜单
            const navLinks = mainNav.querySelectorAll('.nav-link');
            navLinks.forEach(link => {
                link.addEventListener('click', () => {
                    this.closeMobileMenu();
                });
            });

            // 点击遮罩关闭菜单
            const overlay = document.createElement('div');
            overlay.className = 'mobile-menu-overlay';
            overlay.style.cssText = `
                position: fixed;
                top: 0;
                left: 0;
                right: 0;
                bottom: 0;
                background: rgba(0, 0, 0, 0.5);
                opacity: 0;
                visibility: hidden;
                transition: all 0.3s ease;
                z-index: 998;
            `;

            overlay.addEventListener('click', () => {
                this.closeMobileMenu();
            });

            body.appendChild(overlay);
            this.menuOverlay = overlay;

            // ESC键关闭菜单
            document.addEventListener('keydown', (e) => {
                if (e.key === 'Escape' && this.menuOpen) {
                    this.closeMobileMenu();
                }
            });
        }
    }

    /**
     * 切换移动端菜单
     */
    toggleMobileMenu() {
        const menuToggle = document.getElementById('mobileMenuToggle');
        const mainNav = document.querySelector('.main-nav');
        const body = document.body;

        this.menuOpen = !this.menuOpen;

        if (this.menuOpen) {
            menuToggle.classList.add('active');
            mainNav.classList.add('active');
            body.style.overflow = 'hidden';

            // 显示遮罩
            this.menuOverlay.style.opacity = '1';
            this.menuOverlay.style.visibility = 'visible';
        } else {
            this.closeMobileMenu();
        }
    }

    /**
     * 关闭移动端菜单
     */
    closeMobileMenu() {
        const menuToggle = document.getElementById('mobileMenuToggle');
        const mainNav = document.querySelector('.main-nav');
        const body = document.body;

        menuToggle.classList.remove('active');
        mainNav.classList.remove('active');
        body.style.overflow = '';

        // 隐藏遮罩
        this.menuOverlay.style.opacity = '0';
        this.menuOverlay.style.visibility = 'hidden';

        this.menuOpen = false;
    }

    /**
     * 初始化主题切换
     */
    initializeThemeToggle() {
        const themeToggle = document.getElementById('themeToggle');

        if (themeToggle) {
            // 设置初始主题
            this.applyTheme(this.theme);

            themeToggle.addEventListener('click', () => {
                this.toggleTheme();
            });

            // 监听系统主题变化
            if (window.matchMedia) {
                const darkModeQuery = window.matchMedia('(prefers-color-scheme: dark)');
                darkModeQuery.addListener((e) => {
                    if (!localStorage.getItem('theme')) {
                        this.theme = e.matches ? 'dark' : 'light';
                        this.applyTheme(this.theme);
                    }
                });
            }
        }
    }

    /**
     * 切换主题
     */
    toggleTheme() {
        this.theme = this.theme === 'light' ? 'dark' : 'light';
        this.applyTheme(this.theme);
        localStorage.setItem('theme', this.theme);

        // 触发主题变化事件
        this.dispatchEvent('themechange', { theme: this.theme });
    }

    /**
     * 应用主题
     */
    applyTheme(theme) {
        const root = document.documentElement;
        const themeToggle = document.getElementById('themeToggle');
        const icon = themeToggle?.querySelector('i');

        if (theme === 'dark') {
            root.setAttribute('data-theme', 'dark');
            if (icon) {
                icon.className = 'fas fa-sun';
            }
        } else {
            root.removeAttribute('data-theme');
            if (icon) {
                icon.className = 'fas fa-moon';
            }
        }
    }

    /**
     * 初始化搜索功能
     */
    initializeSearch() {
        const searchToggle = document.getElementById('searchToggle');
        const searchContainer = document.getElementById('searchContainer');
        const searchInput = document.getElementById('searchInput');
        const searchBtn = document.getElementById('searchBtn');
        const searchSuggestions = document.getElementById('searchSuggestions');

        if (!searchContainer) return;

        // 搜索切换
        if (searchToggle) {
            searchToggle.addEventListener('click', () => {
                this.toggleSearch();
            });
        }

        // 搜索输入
        if (searchInput) {
            searchInput.addEventListener('input', this.debounce((e) => {
                this.handleSearchInput(e.target.value);
            }, 300));

            searchInput.addEventListener('keydown', (e) => {
                if (e.key === 'Enter') {
                    this.performSearch(e.target.value);
                } else if (e.key === 'Escape') {
                    this.closeSearch();
                }
            });
        }

        // 搜索按钮
        if (searchBtn) {
            searchBtn.addEventListener('click', () => {
                const query = searchInput?.value.trim();
                if (query) {
                    this.performSearch(query);
                }
            });
        }

        // 点击外部关闭搜索
        document.addEventListener('click', (e) => {
            if (!searchContainer.contains(e.target) && !searchToggle?.contains(e.target)) {
                this.closeSearch();
            }
        });
    }

    /**
     * 切换搜索
     */
    toggleSearch() {
        const searchContainer = document.getElementById('searchContainer');
        const searchInput = document.getElementById('searchInput');

        this.searchOpen = !this.searchOpen;

        if (this.searchOpen) {
            searchContainer.classList.add('active');
            // searchInput?.focus();
        } else {
            this.closeSearch();
        }
    }

    /**
     * 关闭搜索
     */
    closeSearch() {
        const searchContainer = document.getElementById('searchContainer');
        const searchInput = document.getElementById('searchInput');
        const searchSuggestions = document.getElementById('searchSuggestions');

        searchContainer.classList.remove('active');
        searchInput.value = '';
        searchSuggestions.style.display = 'none';
        this.searchOpen = false;
    }

    /**
     * 处理搜索输入
     */
    handleSearchInput(query) {
        if (!query.trim()) {
            this.hideSearchSuggestions();
            return;
        }

        // 获取搜索建议
        const suggestions = this.getSearchSuggestions(query);
        this.showSearchSuggestions(suggestions);
    }

    /**
     * 获取搜索建议
     */
    getSearchSuggestions(query) {
        const allSuggestions = [
            '免费图片', '免费字体', '免费图标', '免费视频',
            'Pixabay', 'Unsplash', 'Google Fonts', 'Font Awesome',
            '背景生成器', '在线工具', '设计资源', '素材下载'
        ];

        return allSuggestions
            .filter(suggestion =>
                suggestion.toLowerCase().includes(query.toLowerCase())
            )
            .slice(0, 5);
    }

    /**
     * 显示搜索建议
     */
    showSearchSuggestions(suggestions) {
        const searchSuggestions = document.getElementById('searchSuggestions');

        if (suggestions.length === 0) {
            this.hideSearchSuggestions();
            return;
        }

        const html = suggestions.map(suggestion => `
            <div class="search-suggestion" data-query="${suggestion}">
                <i class="fas fa-search"></i>
                <span>${suggestion}</span>
            </div>
        `).join('');

        searchSuggestions.innerHTML = html;
        searchSuggestions.style.display = 'block';

        // 绑定点击事件
        searchSuggestions.querySelectorAll('.search-suggestion').forEach(item => {
            item.addEventListener('click', () => {
                const query = item.getAttribute('data-query');
                this.performSearch(query);
            });
        });
    }

    /**
     * 隐藏搜索建议
     */
    hideSearchSuggestions() {
        const searchSuggestions = document.getElementById('searchSuggestions');
        searchSuggestions.style.display = 'none';
    }

    /**
     * 执行搜索
     */
    performSearch(query) {
        if (!query.trim()) return;

        console.log(`🔍 搜索: ${query}`);

        // 如果存在全局的搜索函数，调用它
        if (typeof window.ilovefreeMigration !== 'undefined') {
            window.ilovefreeMigration.handleSearch(query);
        }

        // 关闭搜索
        this.closeSearch();

        // 记录搜索事件
        this.dispatchEvent('search', { query });
    }

    /**
     * 设置滚动效果
     */
    setupScrollEffects() {
        const header = document.querySelector('.site-header');
        let lastScrollY = window.scrollY;
        let ticking = false;

        const updateHeader = () => {
            const scrollY = window.scrollY;

            if (scrollY > 100) {
                header.classList.add('scrolled');
            } else {
                header.classList.remove('scrolled');
            }

            // 隐藏/显示头部（向下滚动隐藏，向上滚动显示）
            if (scrollY > lastScrollY && scrollY > 200) {
                header.classList.add('hidden');
            } else {
                header.classList.remove('hidden');
            }

            lastScrollY = scrollY;
            ticking = false;
        };

        const requestTick = () => {
            if (!ticking) {
                requestAnimationFrame(updateHeader);
                ticking = true;
            }
        };

        window.addEventListener('scroll', requestTick, { passive: true });
    }

    /**
     * 设置图片懒加载
     */
    setupImageLazyLoading() {
        const images = document.querySelectorAll('img[loading="lazy"]');

        if ('IntersectionObserver' in window) {
            const imageObserver = new IntersectionObserver((entries) => {
                entries.forEach(entry => {
                    if (entry.isIntersecting) {
                        const img = entry.target;

                        // 添加加载动画
                        img.classList.add('loading');

                        img.onload = () => {
                            img.classList.remove('loading');
                            img.classList.add('loaded');
                        };

                        // 如果图片已经加载完成
                        if (img.complete) {
                            img.classList.remove('loading');
                            img.classList.add('loaded');
                        }

                        imageObserver.unobserve(img);
                    }
                });
            }, {
                rootMargin: '50px 0px',
                threshold: 0.01
            });

            images.forEach(img => imageObserver.observe(img));
        } else {
            // 降级处理
            images.forEach(img => {
                img.classList.add('loaded');
            });
        }
    }

    /**
     * 设置触摸手势
     */
    setupTouchGestures() {
        if (!this.isMobile) return;

        let touchStartX = 0;
        let touchStartY = 0;
        let touchEndX = 0;
        let touchEndY = 0;

        document.addEventListener('touchstart', (e) => {
            touchStartX = e.changedTouches[0].screenX;
            touchStartY = e.changedTouches[0].screenY;
        }, { passive: true });

        document.addEventListener('touchend', (e) => {
            touchEndX = e.changedTouches[0].screenX;
            touchEndY = e.changedTouches[0].screenY;
            this.handleSwipe();
        }, { passive: true });

        this.touchData = { touchStartX, touchStartY, touchEndX, touchEndY };
    }

    /**
     * 处理滑动手势
     */
    handleSwipe() {
        const { touchStartX, touchStartY, touchEndX, touchEndY } = this.touchData;

        const deltaX = touchEndX - touchStartX;
        const deltaY = touchEndY - touchStartY;
        const minSwipeDistance = 50;

        // 水平滑动
        if (Math.abs(deltaX) > Math.abs(deltaY) && Math.abs(deltaX) > minSwipeDistance) {
            if (deltaX > 0) {
                // 向右滑动 - 可以打开菜单
                if (touchStartX < 50 && !this.menuOpen) {
                    this.toggleMobileMenu();
                }
            } else {
                // 向左滑动 - 可以关闭菜单
                if (this.menuOpen) {
                    this.closeMobileMenu();
                }
            }
        }
    }

    /**
     * 初始化性能优化
     */
    initializePerformanceOptimizations() {
        // 节流滚动事件
        let scrollTimeout;
        window.addEventListener('scroll', () => {
            if (scrollTimeout) {
                window.cancelAnimationFrame(scrollTimeout);
            }
            scrollTimeout = window.requestAnimationFrame(() => {
                // 滚动相关的优化处理
                this.updateScrollBasedAnimations();
            });
        }, { passive: true });

        // 预加载关键资源
        this.preloadCriticalResources();

        // 设置页面可见性API
        this.setupVisibilityAPI();
    }

    /**
     * 更新基于滚动的动画
     */
    updateScrollBasedAnimations() {
        const scrolled = window.scrollY;
        const windowHeight = window.innerHeight;

        // 视差效果
        const heroVisual = document.querySelector('.hero-visual');
        if (heroVisual && scrolled < windowHeight) {
            const speed = 0.5;
            const yPos = -(scrolled * speed);
            heroVisual.style.transform = `translateY(${yPos}px)`;
        }

        // 渐入动画
        const animatedElements = document.querySelectorAll('.animate-on-scroll');
        animatedElements.forEach(element => {
            const elementTop = element.offsetTop;
            const elementHeight = element.offsetHeight;

            if (scrolled + windowHeight > elementTop + elementHeight * 0.2) {
                element.classList.add('animated');
            }
        });
    }

    /**
     * 预加载关键资源
     */
    preloadCriticalResources() {
        const criticalResources = [
            'assets/images/logo.png',
            // 其他关键资源
        ];

        criticalResources.forEach(url => {
            const link = document.createElement('link');
            link.rel = 'preload';
            link.as = 'image';
            link.href = url;
            document.head.appendChild(link);
        });
    }

    /**
     * 设置页面可见性API
     */
    setupVisibilityAPI() {
        document.addEventListener('visibilitychange', () => {
            if (document.hidden) {
                // 页面隐藏时暂停动画和定时器
                this.pauseAnimations();
            } else {
                // 页面可见时恢复动画
                this.resumeAnimations();
            }
        });
    }

    /**
     * 暂停动画
     */
    pauseAnimations() {
        // 暂停CSS动画
        document.body.style.animationPlayState = 'paused';

        // 清除定时器
        if (this.scrollTimeout) {
            clearTimeout(this.scrollTimeout);
        }
    }

    /**
     * 恢复动画
     */
    resumeAnimations() {
        // 恢复CSS动画
        document.body.style.animationPlayState = 'running';
    }

    /**
     * 分类动画增强
     */
    setupCategoryAnimations() {
        const categories = document.querySelectorAll('.content-section');

        // 使用Intersection Observer实现滚动触发动画
        const observerOptions = {
            threshold: 0.1,
            rootMargin: '0px 0px -50px 0px'
        };

        const categoryObserver = new IntersectionObserver((entries) => {
            entries.forEach((entry, index) => {
                if (entry.isIntersecting) {
                    setTimeout(() => {
                        entry.target.style.animationPlayState = 'running';
                    }, index * 100);
                }
            });
        }, observerOptions);

        categories.forEach(category => {
            // 初始状态暂停动画
            category.style.animationPlayState = 'paused';
            categoryObserver.observe(category);
        });
    }

    /**
     * 标签交互增强
     */
    setupTagInteractions() {
        const tagButtons = document.querySelectorAll('.tag-btn');

        tagButtons.forEach(button => {
            // 添加点击波纹效果
            button.addEventListener('click', (e) => {
                this.createRipple(e, button);
            });

            // 键盘导航支持
            button.addEventListener('keydown', (e) => {
                if (e.key === 'Enter' || e.key === ' ') {
                    e.preventDefault();
                    button.click();
                }
            });
        });
    }

    /**
     * 导航卡片增强
     */
    setupNavigationEnhancements() {
        // 只选择内容区域的导航卡片，排除粘性导航栏
        const navCards = document.querySelectorAll('.nav-all-container .nav-link');

        navCards.forEach(card => {
            // 添加3D倾斜效果
            card.addEventListener('mousemove', (e) => {
                this.addTiltEffect(e, card);
            });

            card.addEventListener('mouseleave', () => {
                this.removeTiltEffect(card);
            });

            // 添加点击反馈
            card.addEventListener('click', () => {
                this.addClickFeedback(card);
            });
        });
    }

    /**
     * 可访问性功能
     */
    setupAccessibilityFeatures() {
        // 焦点管理
        this.setupFocusManagement();

        // ARIA标签增强
        this.enhanceAriaLabels();

        // 键盘导航
        this.setupKeyboardNavigation();
    }

    /**
     * 创建波纹效果
     */
    createRipple(event, element) {
        const ripple = document.createElement('span');
        const rect = element.getBoundingClientRect();
        const size = Math.max(rect.width, rect.height);
        const x = event.clientX - rect.left - size / 2;
        const y = event.clientY - rect.top - size / 2;

        ripple.style.width = ripple.style.height = size + 'px';
        ripple.style.left = x + 'px';
        ripple.style.top = y + 'px';
        ripple.classList.add('ripple');

        element.appendChild(ripple);

        // 动画结束后移除元素
        setTimeout(() => {
            ripple.remove();
        }, 600);
    }

    /**
     * 添加3D倾斜效果
     */
    addTiltEffect(event, card) {
        const rect = card.getBoundingClientRect();
        const x = event.clientX - rect.left;
        const y = event.clientY - rect.top;

        const centerX = rect.width / 2;
        const centerY = rect.height / 2;

        const rotateX = (y - centerY) / 10;
        const rotateY = (centerX - x) / 10;

        card.style.transform = `perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) translateZ(10px)`;
    }

    /**
     * 移除3D倾斜效果
     */
    removeTiltEffect(card) {
        card.style.transform = '';
    }

    /**
     * 添加点击反馈
     */
    addClickFeedback(card) {
        card.style.transform = 'scale(0.98)';
        setTimeout(() => {
            card.style.transform = '';
        }, 150);
    }

    /**
     * 设置焦点管理
     */
    setupFocusManagement() {
        const focusableElements = document.querySelectorAll(
            'button, [href], select, textarea, [tabindex]:not([tabindex="-1"])'
        );

        focusableElements.forEach(element => {
            element.addEventListener('focus', () => {
                element.classList.add('focused');
            });

            element.addEventListener('blur', () => {
                element.classList.remove('focused');
            });
        });
    }

    /**
     * 增强ARIA标签
     */
    enhanceAriaLabels() {
        // 为分类标题添加更好的描述
        const categoryTitles = document.querySelectorAll('.category-title');
        categoryTitles.forEach(title => {
            const categoryName = title.querySelector('.category-name')?.textContent;
            if (categoryName) {
                title.setAttribute('aria-label', `分类：${categoryName}`);
            }
        });

        // 为标签按钮添加状态描述
        const tagButtons = document.querySelectorAll('.tag-btn');
        tagButtons.forEach(button => {
            const isActive = button.classList.contains('active');
            const tagName = button.textContent.trim();
            const status = isActive ? '已选中' : '未选中';
            button.setAttribute('aria-label', `${tagName}标签，${status}`);
        });
    }

    /**
     * 设置键盘导航
     */
    setupKeyboardNavigation() {
        document.addEventListener('keydown', (e) => {
            // Alt + 数字键快速跳转到分类
            if (e.altKey && e.key >= '1' && e.key <= '9') {
                const categoryIndex = parseInt(e.key) - 1;
                const categories = document.querySelectorAll('.content-section');

                if (categories[categoryIndex]) {
                    e.preventDefault();
                    categories[categoryIndex].scrollIntoView({
                        behavior: 'smooth',
                        block: 'start'
                    });
                    categories[categoryIndex].querySelector('.category-title').focus();
                }
            }
        });
    }

    /**
     * 绑定全局事件
     */
    bindGlobalEvents() {
        // 窗口大小变化
        window.addEventListener('resize', this.debounce(() => {
            this.handleResize();
        }, 250));

        // 错误处理
        window.addEventListener('error', (e) => {
            this.handleError(e);
        });

        // 性能监控
        this.setupPerformanceMonitoring();
    }

    /**
     * 处理窗口大小变化
     */
    handleResize() {
        const wasMobile = this.isMobile;
        this.isMobile = window.innerWidth <= 768;

        // 移动端/桌面端切换
        if (wasMobile !== this.isMobile) {
            if (!this.isMobile && this.menuOpen) {
                this.closeMobileMenu();
            }
            this.dispatchEvent('viewchange', { isMobile: this.isMobile });
        }
    }

    /**
     * 处理错误
     */
    handleError(error) {
        console.error('页面错误:', error);

        // 可以发送错误报告到监控服务
        if (typeof gtag !== 'undefined') {
            gtag('event', 'error', {
                'error_message': error.message,
                'error_filename': error.filename,
                'error_lineno': error.lineno
            });
        }
    }

    /**
     * 设置性能监控
     */
    setupPerformanceMonitoring() {
        // 页面加载性能
        window.addEventListener('load', () => {
            if ('performance' in window) {
                const navigation = performance.getEntriesByType('navigation')[0];
                const loadTime = navigation.loadEventEnd - navigation.navigationStart;

                console.log(`📊 页面加载时间: ${loadTime}ms`);

                // 发送性能数据
                if (typeof gtag !== 'undefined') {
                    gtag('event', 'page_load_time', {
                        value: loadTime,
                        custom_parameter: 'enhanced_interactions'
                    });
                }
            }
        });

        // 长任务监控
        if ('PerformanceObserver' in window) {
            const observer = new PerformanceObserver((list) => {
                list.getEntries().forEach((entry) => {
                    if (entry.duration > 50) {
                        console.warn(`⚠️ 长任务检测: ${entry.duration}ms`);
                    }
                });
            });

            try {
                observer.observe({ entryTypes: ['longtask'] });
            } catch (e) {
                // 某些浏览器可能不支持
            }
        }
    }

    /**
     * 触发自定义事件
     */
    dispatchEvent(eventName, detail = {}) {
        const event = new CustomEvent(eventName, { detail });
        document.dispatchEvent(event);
    }

    /**
     * 防抖函数
     */
    debounce(func, wait) {
        let timeout;
        return function executedFunction(...args) {
            const later = () => {
                clearTimeout(timeout);
                func(...args);
            };
            clearTimeout(timeout);
            timeout = setTimeout(later, wait);
        };
    }

    /**
     * 注入CSS样式
     */
    injectStyles() {
        const style = document.createElement('style');
        style.textContent = `
            .ripple {
                position: absolute;
                border-radius: 50%;
                background: rgba(255, 255, 255, 0.5);
                transform: scale(0);
                animation: ripple-animation 0.6s ease-out;
                pointer-events: none;
                z-index: 1;
            }

            @keyframes ripple-animation {
                to {
                    transform: scale(4);
                    opacity: 0;
                }
            }

            .focused {
                outline: 2px solid var(--ilovefree-blue, #0396FF);
                outline-offset: 2px;
            }

            .site-header.scrolled {
                background: rgba(255, 255, 255, 0.98);
                backdrop-filter: blur(20px);
                box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
            }

            .site-header.hidden {
                transform: translateY(-100%);
            }

            .search-container.active {
                transform: scale(1.02);
                box-shadow: 0 10px 40px rgba(3, 150, 255, 0.2);
            }

            .search-suggestions {
                position: absolute;
                top: 100%;
                left: 0;
                right: 0;
                background: white;
                border: 1px solid rgba(0, 0, 0, 0.1);
                border-radius: 0 0 12px 12px;
                box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
                max-height: 200px;
                overflow-y: auto;
                z-index: 1000;
            }

            .search-suggestion {
                padding: 12px 16px;
                cursor: pointer;
                display: flex;
                align-items: center;
                gap: 12px;
                transition: background-color 0.2s ease;
            }

            .search-suggestion:hover {
                background-color: rgba(3, 150, 255, 0.05);
            }

            .img.loading {
                opacity: 0;
                filter: blur(5px);
            }

            .img.loaded {
                opacity: 1;
                filter: blur(0);
                transition: opacity 0.3s ease, filter 0.3s ease;
            }

            @media (prefers-reduced-motion: reduce) {
                * {
                    animation-duration: 0.01ms !important;
                    animation-iteration-count: 1 !important;
                    transition-duration: 0.01ms !important;
                }
            }
        `;
        document.head.appendChild(style);
    }
}

/**
 * 初始化增强交互系统
 */
document.addEventListener('DOMContentLoaded', () => {
    // 等待主要迁移系统初始化完成
    setTimeout(() => {
        window.enhancedInteractions = new EnhancedInteractions();
        window.enhancedInteractions.injectStyles();

        // 添加全局方法
        window.toggleMobileMenu = () => window.enhancedInteractions.toggleMobileMenu();
        window.toggleTheme = () => window.enhancedInteractions.toggleTheme();
        window.toggleSearch = () => window.enhancedInteractions.toggleSearch();

        console.log('🚀 所有交互系统已准备就绪');
    }, 100);
});

// 导出模块
if (typeof module !== 'undefined' && module.exports) {
    module.exports = EnhancedInteractions;
}